package com.fita.tencent.entity.weappauth;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 解密数据
 * 
 * @author wangliwang
 *
 */
public class WeappAuth {

    @JsonProperty("openId")
    private String openid;
    
    @JsonProperty("nickName")
    private String nickName;
    
    private Integer gender;
    
    private String province;
    
    private String country;
    
    @JsonProperty("avatarUrl")
    private String avatar;
    
    @JsonProperty("unionId")
    private String unionid;
    
    public Watermark watermark;
    
    /**
     * The default constructor
     */
    public WeappAuth() {
        
    }
    
    /**
     * 
     * @return
     */
    @JsonIgnore
    public boolean isValid() {
        return StringUtils.isNotEmpty(this.openid) &&
               StringUtils.isNotEmpty(this.nickName) &&
               StringUtils.isNotEmpty(this.avatar) &&
               StringUtils.isNoneBlank(this.unionid);
    }
    
    /**
     * check data whether valid
     * 
     * @param appid
     * @return
     */
    @JsonIgnore
    public boolean matches(String appid) {
        return StringUtils.equals(appid, this.watermark.getAppid());
    }
    
    /**
     * describe some data
     * 
     * @return
     */
    public Map<String, Object> describe() {
        
        Map<String, Object> data = new LinkedHashMap<String, Object>();
        
        data.put("openid", openid);
        data.put("nickName", nickName);
        data.put("gender", gender);
        data.put("province", province);
        data.put("country", country);
        data.put("avatar", avatar);
        data.put("unionid", unionid);
        
        return data;
    }
    
    /**
     * 
     * @return
     */
    public Map<String, Object> describeAuthLogin() {
        Map<String, Object> data = new LinkedHashMap<String, Object>();
        data.put("avator", this.avatar);
        data.put("nickname", this.nickName);
        data.put("sex", this.gender);
        data.put("country", this.country);
        data.put("province", this.province);
        return data;
    }

    /**
     * @return the openid
     */
    public String getOpenid() {
        return openid;
    }

    /**
     * @return the nickName
     */
    public String getNickName() {
        return nickName;
    }

    /**
     * @return the gender
     */
    public Integer getGender() {
        return gender;
    }

    /**
     * @return the province
     */
    public String getProvince() {
        return province;
    }

    /**
     * @return the country
     */
    public String getCountry() {
        return country;
    }

    /**
     * @return the avatar
     */
    public String getAvatar() {
        return avatar;
    }

    /**
     * @return the unionid
     */
    public String getUnionid() {
        return unionid;
    }

    /**
     * @return the watermark
     */
    public Watermark getWatermark() {
        return watermark;
    }

    /**
     * @param openid the openid to set
     */
    public void setOpenid(String openid) {
        this.openid = openid;
    }

    /**
     * @param nickName the nickName to set
     */
    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(Integer gender) {
        this.gender = gender;
    }

    /**
     * @param province the province to set
     */
    public void setProvince(String province) {
        this.province = province;
    }

    /**
     * @param country the country to set
     */
    public void setCountry(String country) {
        this.country = country;
    }

    /**
     * @param avatar the avatar to set
     */
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    /**
     * @param unionid the unionid to set
     */
    public void setUnionid(String unionid) {
        this.unionid = unionid;
    }

    /**
     * @param watermark the watermark to set
     */
    public void setWatermark(Watermark watermark) {
        this.watermark = watermark;
    }
    
}
